package cn.lunkr.sdkdemo.ui.phone

import android.content.Context
import androidx.navigation.NavGraph
import androidx.navigation.NavGraphNavigator
import androidx.navigation.NavigatorProvider
import androidx.navigation.fragment.FragmentNavigator
import cn.lunkr.mailui.ui.MailsBarFragment
import cn.lunkr.mailui.ui.MyFragment
import cn.lunkr.mailui.ui.calendar.ui.ScheduleBarFragment
import cn.lunkr.sdkdemo.R
import cn.lunkr.sdkdemo.util.FixFragmentNavigator

class InitPhoneNavGraph {
    fun init(context: Context, provider: NavigatorProvider?, fixFragmentNavigator: FixFragmentNavigator): NavGraph {
        val navGraph = NavGraph(NavGraphNavigator(provider!!))
        //用自定义的导航器来创建目的地
        val mailDest: FragmentNavigator.Destination = fixFragmentNavigator.createDestination()
        mailDest.id = R.id.tab_mails
        mailDest.label = context.getString(R.string.inbox)
        mailDest.setClassName(MailsBarFragment::class.java.canonicalName)
        navGraph.addDestination(mailDest)

        val contactsDest: FragmentNavigator.Destination = fixFragmentNavigator.createDestination()
        contactsDest.id = R.id.tab_contacts
        contactsDest.label = context.getString(R.string.contacts)
        contactsDest.setClassName(cn.lunkr.mailui.ui.Contact1sBarFragment::class.java.canonicalName)
        navGraph.addDestination(contactsDest)

        val calendarDest: FragmentNavigator.Destination = fixFragmentNavigator.createDestination()
        calendarDest.id = R.id.tab_calendar
        calendarDest.label = context.getString(R.string.calendar)
        calendarDest.setClassName(ScheduleBarFragment::class.java.canonicalName)
        navGraph.addDestination(calendarDest)

        val meDest: FragmentNavigator.Destination = fixFragmentNavigator.createDestination()
        meDest.id = R.id.tab_me
        meDest.label = context.getString(R.string.me)
        meDest.setClassName(MyFragment::class.java.canonicalName)
        navGraph.addDestination(meDest)

        navGraph.setStartDestination(mailDest.id)
        return navGraph
    }
}